package com.itserver.service.sys.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itserver.mapper.sys.RoleMapper;
import com.itserver.pojo.PageResult;
import com.itserver.pojo.sys.QueryRole;
import com.itserver.pojo.sys.Role;
import com.itserver.service.sys.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private  RoleMapper roleMapper;

    @Override
    public PageResult<Role> page(QueryRole queryRole) {
        PageHelper.startPage(queryRole.getPage(),queryRole.getPageSize());
        List<Role> roles = roleMapper.page(queryRole);
        Page<Role> page = (Page<Role>) roles;

        return new PageResult<>(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Role role) {
        roleMapper.add(role);
    }

    @Override
    public void update(Role role) {
        roleMapper.update(role);
    }

    @Override
    public void delete(List<Integer> ids) {
        roleMapper.delete(ids);
    }

    @Override
    public Role getById(Integer id) {
        return roleMapper.getById(id);
    }

    @Override
    public List<Role> getByIdsMenu(List<Integer> roleIds) {
        return roleMapper.getByIdsMenu(roleIds);
    }
}
